﻿// ***************************************************************************
// YAMM
// Copyright (C) 2008 Christian Schmiljun, Frank Weißenborn 
// http://www.codeplex.com/YAMM 
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// ***************************************************************************

using System;
using System.Collections.Generic;
using System.Windows.Forms;

using WeifenLuo.WinFormsUI.Docking;

using YAMM.PlugIn;

namespace YAMM.PlugInManagement.Windows
{
    class Window : DockContent, IWindow
    {
        Control content;

        #region IWindow Member

        public string Caption
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }

        public System.Windows.Forms.Control Content
        {
            get { return content; }
        }

        public Guid Identifier
        {
            get;
            internal set;
        }

        bool IWindow.Visible
        {
            get
            {
                return IsHidden;
            }
            set
            {
                if (value)
                    base.Show();
                else
                    base.Hide();
            }
        }

        public event EventHandler Hidden;


        #endregion

        public Window(Guid identifier, string caption) : base()
        {
            this.Identifier = identifier;
            this.Caption = caption;
            this.content = new Panel();
            this.content.Dock = DockStyle.Fill;
            this.Controls.Add(this.content);
            this.HideOnClose = true;

            this.VisibleChanged += new EventHandler(Window_VisibleChanged);            
        }       

        public Window(Guid identifier, string caption, Control content) : base()
        {
            this.Identifier = identifier;
            this.Caption = caption;
            this.content = content;
            this.content.Dock = DockStyle.Fill;
            this.Controls.Add(this.content);
            this.HideOnClose = true;

            base.VisibleChanged += new EventHandler(Window_VisibleChanged);            
        }

        void Window_VisibleChanged(object sender, EventArgs e)
        {
            if (base.IsHidden && Hidden != null)
                Hidden(this, EventArgs.Empty);
        }

    }
}
